/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package slisfx.exception;

import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import slisfx.Globals;
import slisfx.devices.AlarmViewFX;
import slisfx.devices.LightViewFX;
import slisfx.devices.ThermoViewFX;
import slisfx.resources.Load;
import slisfx.screens.*;

/**
 *
 * @author Rebecca
 */
public class SLISExceptionFX extends Application implements Globals{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        launch(args);
    }
    
    private String message;
    private String location;
    
    public SLISExceptionFX(String m, String l){
        message = m;
        location = l;
    }
    
    @Override
    public void start(final Stage primaryStage) {
        try {
            primaryStage.setTitle("Error!"); 
            BorderPane mainWindow = new BorderPane();
            Text errorMessage = new Text(message);
            errorMessage.setFont(Font.font("Amble CN", FontWeight.BOLD, 18));
            Button btn = new Button("OK!");
            
            Image im = new Image(new Load().loadFile("error.png")); 
            ImageView iv1 = new ImageView();
            iv1.setImage(im);
            
            HBox imageBox = new HBox();
            imageBox.setPadding(new Insets(10, 10, 10, 10));
            imageBox.setSpacing(0);
            imageBox.getChildren().add(new Rectangle(255,100, Color.GRAY));
            imageBox.getChildren().add(iv1);
            imageBox.getChildren().add(new Rectangle(100,100, Color.GRAY));
            
            mainWindow.setTop(new Rectangle(830,50, Color.BLACK));
            mainWindow.setBottom(new Rectangle(830,50, Color.BLACK));
            mainWindow.setLeft(new Rectangle(50,350, Color.BLACK));
            mainWindow.setRight(new Rectangle(50, 350, Color.BLACK));
            
            btn.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent event) {
                    switch(location){
                        case ADD_USER_SCREEN: new AddUserScreenFX().start(primaryStage);
                            break;
                        case ADMIN_SCREEN: new AdminScreenViewFX().start(primaryStage);
                            break;
                        case ALARM_SCREEN: new AlarmViewFX().start(primaryStage);
                            break;
                        case DEVICE_SCREEN: new DeviceOptionsViewFX().start(primaryStage);
                            break;
                        case LOGIN_SCREEN: new LoginScreenFX().start(primaryStage);
                            break;
                        case LIGHT_SCREEN: new LightViewFX().start(primaryStage);
                            break;
                        case REMOVE_USER_SCREEN: new RemoveUserViewFX().start(primaryStage);
                            break;
                        case SYSTEM_SCREEN: new SystemViewFX().start(primaryStage);
                            break;
                        case THERMO_SCREEN: new ThermoViewFX().start(primaryStage);
                            break;
                    }
                    
                }
            });
            VBox root = new VBox();
            root.setPadding(new Insets(10, 10, 10, 10));
            root.setSpacing(10);
            root.getChildren().add(imageBox);
            root.getChildren().add(errorMessage);
            root.getChildren().add(btn);
            mainWindow.setStyle("-fx-background-color: #808080");
            mainWindow.setCenter(root);
            primaryStage.setScene(new Scene(mainWindow, 100, 100));
            primaryStage.show();
        } catch (IOException ex) {
            Logger.getLogger(SLISExceptionFX.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
